/**
 *  ward @ 2019
 *  harrydeep@wardyan.top
 */
package top.wardyan.wbaseswt.test;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.wb.swt.SWTResourceManager;

import top.wardyan.wbaseswt.action.base.AbstractShell;
import top.wardyan.wbaseswt.util.ShellUtil;
//import top.wardyan.wdev.dbassist.action.table.TableShell;
//import top.wardyan.wdev.dbassist.config.DDA;
//
/**
 * 
 * @author ward 2019年3月9日
 */
public abstract class BaseShell<T extends BaseShell<T>> extends AbstractShell<T>{
	protected Button btnProc;
	protected Button btnView;
	protected Button btnTablefunction;
	protected Button btnfunction;
	protected Button btnTrigger;
	protected Button btnIndex;
	protected Button btnDic;
	protected Composite topCom;
	
	
	private void resize() {
		topCom.setBounds(0, 0, self.getSize().x - 10, 70);
		// 子类继承后需要调用本方法
		//System.out.println(self.getSize().x);
	}

	public BaseShell() {
		super();
		addControlListener(new ControlAdapter() {
			@Override
			public void controlResized(ControlEvent e) {
				resize();
			}
		});
		
		topCom = new Composite(this, SWT.BORDER);
		topCom.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		topCom.setBounds(0, 0, 1024, 70);
		resize();
		
		Button btnTable = new Button(topCom, SWT.NONE);
		btnTable.setBounds(10, 10, 140, 48);
		btnTable.setText("数据表table");
//		btnTable.addSelectionListener(new SelectionAdapter() {
//			@Override
//			public void widgetSelected(SelectionEvent e) {
//				self.switchMenu(new TableShell());
//			}
//			
//		});
		
		btnProc = new Button(topCom, SWT.NONE);
		btnProc.setText("存储过程proc");
		btnProc.setBounds(156, 10, 140, 48);
		
		btnView = new Button(topCom, SWT.NONE);
		btnView.setText("视图view");
		btnView.setBounds(302, 10, 140, 48);
		
		btnTablefunction = new Button(topCom, SWT.NONE);
		btnTablefunction.setText("表值函数tablefunc");
		btnTablefunction.setBounds(448, 10, 140, 48);
		
		btnfunction = new Button(topCom, SWT.NONE);
		btnfunction.setText("标量函数func");
		btnfunction.setBounds(594, 10, 140, 48);
		
		btnTrigger = new Button(topCom, SWT.NONE);
		btnTrigger.setText("触发器trigger");
		btnTrigger.setBounds(740, 10, 140, 48);
		
		btnIndex = new Button(topCom, SWT.NONE);
		btnIndex.setText("索引index");
		btnIndex.setBounds(886, 10, 140, 48);
		
		btnDic = new Button(topCom, SWT.NONE);
		btnDic.setText("数据字典dic");
		btnDic.setBounds(1032, 10, 140, 48);
		
		this.init();
	}
	
	public BaseShell(Integer style) {
		super(style);
		this.init();
	}
	
	protected void init() {
		createContents();
		this.setMaximized(true);
	}
	
	
//	/**
//	 * 设置系统标题. 推荐子类重写
//	 */
//	protected String getTitle() {
//		return DDA.SYSTEMCONFIG.SystemName + " " + DDA.SYSTEMCONFIG.BuildVersion + " " + title();
//	}
	
	protected abstract String title();


	private void createContents() {
		this.setSize(1024, 720);
		ShellUtil.center(this);
	}
	
	protected void switchMenu(BaseShell<? extends BaseShell<?>> target) {
		Rectangle rec = self.getBounds();
		boolean max = self.getMaximized();
		self.dispose();
		target.setBounds(rec);
		target.setMaximized(max);
		target.go();
	}
}
